package com.white.commonlib.adapter.recycle;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;

/**
 * Created by ytf on 2017/12/17 017.
 * Description:
 */

public abstract class SimpleTextAdapter<T extends SimpleTextProvider> extends BaseNormalAdapter<T>
{
    private @LayoutRes int layout;

    public SimpleTextAdapter(Context context, List<T> data, int layout)
    {
        super(context, data);
        this.layout = layout;
    }

    @Override
    public RecyclerView.ViewHolder getCustomHolder(Context context, ViewGroup parent, int viewType, View v)
    {
        return new VH(context, v);
    }

    @Override
    public int getCustomView(int viewType)
    {
        return layout;
    }

    public class VH extends BaseViewHolder<T>
    {
        public TextView tv;

        public VH(Context context, View v)
        {
            super(context, v);
            if(v instanceof ViewGroup)
            {
                tv = (TextView) ((ViewGroup)v).getChildAt(0);
            }else
            {
                tv = (TextView) v;
            }
        }

        @Override
        public void setContent(T data, int position)
        {
            tv.setText(data.getStr());
            setHolder(this, data, position);
        }
    }

    public void setHolder(VH holder, T data, int position){}
}
